$(function () {
    load();
})

//返回
function fh() {
    localStorage.removeItem("mdesignprocedureCha");
    location.href = "../../li_meng/mdesignprocedureCha.html";
}

//表单
function load() {
    let mdesignprocedureCha = JSON.parse(localStorage.getItem("mdesignprocedureCha"));
    $("#rname").val(mdesignprocedureCha.checker);
    $("#date").val(mdesignprocedureCha.checktime);
    $("#register").val(mdesignprocedureCha.register);
    $("#registerTime").val(mdesignprocedureCha.registertime);
    //设计单编号
    $("#designid").text(mdesignprocedureCha.designid);
    $("#sjdID").text(mdesignprocedureCha.designid);
    //设计人
    $("#designer").text(mdesignprocedureCha.designer);
    //产品编号
    $("#productid").text(mdesignprocedureCha.productid);
    //产品名称
    $("#productname").text(mdesignprocedureCha.productname);
    //总工时
    $("#costpricesum").text(mdesignprocedureCha.costpricesum);
    //设计要求
    $("#proceduredescribe").text(mdesignprocedureCha.proceduredescribe);
    $("#modulecostpricesum").text(mdesignprocedureCha.modulecostpricesum);
    $("#checksuggestion").val(mdesignprocedureCha.checksuggestion);

    $.post("/Mdesignproceduredetails.do/ChaById", {id: mdesignprocedureCha.id}, function (sdata) {
        console.log(sdata)
        let str = " <tr >\n" +
            "           <th>序号</th>\n" +
            "           <th>工序名称</th>\n" +
            "           <th>工序编号</th>\n" +
            "           <th>描述</th>\n" +
            "           <th>工时数</th>\n" +
            "           <th>工时成本小计(元)</th>\n" +
            "           <th>物料成本小计(元)</th>\n" +
            "           <th>审核</th>\n" +
            "       </tr>\n";

        $.each(sdata, function (index, item) {
            let s= JSON.stringify(item)
            str +=
                "  <tr>\n" +
                "      <td>" + item.detailsnumber + "</td>\n" +
                "      <td>" + item.procedurename + "</td>\n" +
                "      <td>" + item.procedureid + "</td>\n" +
                "      <td>" + item.proceduredescribe + "</td>\n" +
                "      <td>" + item.labourhouramount + "</td>\n" +
                "      <td>" + item.costprice + "</td>\n" +
                "      <td>" + item.modulesubtotal + "</td>\n" +
                "      <th><input type='button' value='查看' onclick='Cha(" + s + ")'></th>\n" +
                "  </tr>";
        })
        $("#tableAdd").html(str);
    })
}

function Cha(op) {
    $("#XQModal").modal("show");
    $("#gxName").text(op.procedurename);
    $("#djrName").text(op.register);
    $("#djsjDate").text(op.registertime);

    let sstr = " <tr >\n" +
        "           <th>序号</th>\n" +
        "           <th>物料名称</th>\n" +
        "           <th>物料编号</th>\n" +
        "           <th>描述</th>\n" +
        "           <th>本工序数量</th>\n" +
        "           <th>单位</th>\n" +
        "           <th>单价(元)</th>\n" +
        "           <th>小计(元)</th>\n" +
        "       </tr>\n";
    $.post("/Mdesignproceduremoduledetails.do/limengMdesignproceduremoduledetailsSHCha", {id: op.id}, function (sdate) {
        $.each(sdate, function (index, item) {
            sstr += "  <tr>\n" +
                "      <td>" + item.detailsnumber + "</td>\n" +
                "      <td>" + item.productname + "</td>\n" +
                "      <td>" + item.productid + "</td>\n" +
                "      <td>" + item.productdescribe + "</td>\n" +
                "      <td>" + item.amount + "</td>\n" +
                "      <td>" + item.amountunit + "</td>\n" +
                "      <td>" + item.costprice + "</td>\n" +
                "      <td>" + item.subtotal + "</td>\n" +
                "  </tr>";
        })
        $("#tm01").html(sstr);
    })
}



